package com.wangtao.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

public class MappedByteBuffer {
    public static void main(String[] args) throws IOException {
        RandomAccessFile rw = new RandomAccessFile("1.txt", "rw");

        FileChannel fileChannel = rw.getChannel();

        //读写模式 起始位置 映射到内存的大小
        java.nio.MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 5);
        mappedByteBuffer.put(0, (byte) 'H');
        mappedByteBuffer.put(3, (byte) '9');
        mappedByteBuffer.put(5, (byte) 'Y');

        rw.close();
    }
}
